package com.hjms.common.entity.exception;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author 何杨谊
 * @description: TODO
 * @date 2023/2/8 15:22
 */
@Data
public class ErrorResult {

    /**
     * http状态码：200=成功；401=未授权；403=无权限；412=先决条件不满足；500=服务异常
     */
    private Integer status;
    /**
     * 消息提示
     */
    private String message;
    /**
     * 业务code
     */
    private String code;

    /**
     * 401=未授权
     * @param message
     * @param code
     * @return
     */
    public static ErrorResult Unauthorized401(String message,String code) {
        ErrorResult resultData = new ErrorResult();
        resultData.setStatus(401);
        resultData.setMessage(message);
        resultData.setCode(code);
        return resultData;
    }

    /**
     * 403=无权限
     * @param message
     * @param code
     * @return
     */
    public static ErrorResult Forbidden403(String message,String code) {
        ErrorResult resultData = new ErrorResult();
        resultData.setStatus(403);
        resultData.setMessage(message);
        resultData.setCode(code);
        return resultData;
    }

    /**
     * 412=先决条件不满足
     * @param message
     * @param code
     * @return
     */
    public static ErrorResult Precondition412(String message,String code) {
        ErrorResult resultData = new ErrorResult();
        resultData.setStatus(412);
        resultData.setMessage(message);
        resultData.setCode(code);
        return resultData;
    }

    /**
     * 500=服务异常
     * @param message
     * @return
     */
    public static ErrorResult ServerError500(String message) {
        ErrorResult resultData = new ErrorResult();
        resultData.setStatus(500);
        resultData.setMessage(message);
        resultData.setCode("server.error");
        return resultData;
    }
}
